package buildcode.support.plugin;

import java.util.List;

import org.apache.commons.lang3.StringUtils;

import buildcode.Context;
import buildcode.build.IPlugin;
import buildcode.config.EntityExportConfig;
import buildcode.database.DataBaseTable;
import buildcode.database.convert.NameConvert;
import buildcode.database.convert.UnderLineToCamelCaseConvert;
import buildcode.language.Type;
import buildcode.util.CommonUtil;

public class TrimTablePrefixPlugin implements IPlugin {
    NameConvert namceConvert = new UnderLineToCamelCaseConvert();

    @Override
    public Type beforeExport(Type type, String contextId, List<DataBaseTable> bases, EntityExportConfig entityConfig) {
        String name = type.getTypeName();
        name = StringUtils.removeStart(name, StringUtils.defaultString(CommonUtil.firstUpper(namceConvert.convert(Context.getTablePrfix())), ""));
        type.setTypeName(name);
        return type;
    }

    public TrimTablePrefixPlugin() {
    }

}
